<?xml version="1.0" encoding="UTF-8"?>
<%@ page contentType="text/xml;charset=utf-8"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.tomato.dao.*"%>
<%@ page import="com.tomato.bean.*"%>
<%@ page import="com.tomato.servlet.*"%>
<%@ page import="javax.jdo.*"%>
<%@ page import="com.google.appengine.api.datastore.Blob"%>

<lists> 
<%
 	request.setCharacterEncoding("utf-8");
	List<String> list = new ArrayList();
 	//list.add(request.getParameter("condition_1"));
  	//list.add(request.getParameter("condition_2"));
  	list.add("date");
  	list.add("title");
  	list.add("count");
  	
  	PersistenceManager pm = PMF.get().getPersistenceManager();
  	Query query = pm.newQuery(Ebook.class);
  	for(String str : list) {
  		if (str.equals("count")) {
  	  		query.setOrdering("count desc");
  	  	} else if (str.equals("date")) {
  	  		query.setOrdering("date desc");
  	  	} else if(str.equals("title")) {
  	  		query.setOrdering("count desc");
  	  	}
  	  	List<Ebook> ebook = (List<Ebook>) query.execute();
  	  	%>
  	<data> 
  	<%  	
  	for (Ebook ebooks : ebook) {
  		byte[] b = ebooks.getEbook().getBytes();
  		String strEbook = new String(b,"utf-8");
  		Date date = ebooks.getDate();
  		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  		String strDate = df.format(date);
 %> 


	<<%=str%>>
	<id><%=ebooks.getId()%></id> 
	<genre><%=ebooks.getGenre()%></genre>
	<title><%=ebooks.getTitle()%></title> 
	<author><%=ebooks.getAuthor()%></author>
	<description><%=ebooks.getDescription()%></description> 
	<ebook><%=strEbook%></ebook>
	<%if(ebooks.getImage() != null) {%>
	<url><%=request.getServerName()%>/e_book?method=show&amp;id=<%=ebooks.getId()%></url>
	<%} else {%>
	<url>null</url>
	<%}%>
	<count><%=ebooks.getCount()%></count> 
	<date><%=strDate%></date>
	</<%=str%>>
<%
 	}
%>
</data> 
<%
  	}
%> 
</lists>
